unit KnjigaIzdanihRacunovRDM;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
  DBClient, StdVcl, FMTBcd, Provider, alProvider, DB, SqlExpr,
  PoslovanjeSrv_TLB,
  DokumentRDM;

type
  TrdmKnjigaIzdanihRacunov = class(TrdmDokument, IrdmKnjigaIzdanihRacunov)
  private
    { Private declarations }
  protected
    class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
    function GetSelectCommandText(DataSet: TSQLDataSet): string; override;
    function Get_RazredID(const ProviderName: WideString): Integer; safecall;
    function GetTableName: string; override;
    procedure RefreshRecord(const Session: ISession;
      const ProviderName: WideString; ID: Integer); safecall;
    procedure Renumber(const Session: ISession; const FieldName,
      SortFieldName: WideString; StartValue, EndValue: Integer); safecall;
    procedure SetDefaultExpression(DataSet: TDataSet); override;
    procedure Set_ReadOnly(Value: WordBool); safecall;
    procedure Set_SQLConnection(Value: Integer); safecall;
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  KnjigaIzdanihRacunovFactory: TComponentFactory;

implementation

{$R *.DFM}

uses
  KnjigaIzdanihRacunovReportRDM;

constructor TrdmKnjigaIzdanihRacunov.Create(AOwner: TComponent);
begin
  inherited;
  dspMain.Options := dspMain.Options + [poReadOnly];
end;

function TrdmKnjigaIzdanihRacunov.GetSelectCommandText(
  DataSet: TSQLDataSet): string;
var
  SQL: TStringList;
begin
  SQL := TStringList.Create;
  try
    if DataSet = dsMain then
    begin
      SQL.Add('select');
        SQL.Add('KIR.*');
      SQL.Add('from KNJIGA_IZDANIH_RACUNOV KIR');
      SQL.Add('where KIR.REF_ID = :POSLOVNO_LETO_ID');
    end;
  finally
    Result := Trim(SQL.Text);
    SQL.Free;
  end;
end;

function TrdmKnjigaIzdanihRacunov.GetTableName: string;
begin
  Result := 'KIR';
end;

function TrdmKnjigaIzdanihRacunov.Get_RazredID(
  const ProviderName: WideString): Integer;
begin
  Result := inherited Get_RazredID(ProviderName);
end;

procedure TrdmKnjigaIzdanihRacunov.RefreshRecord(const Session: ISession;
  const ProviderName: WideString; ID: Integer);
begin
  inherited;
end;

procedure TrdmKnjigaIzdanihRacunov.Renumber(const Session: ISession;
  const FieldName, SortFieldName: WideString; StartValue,
  EndValue: Integer);
begin
  inherited;
end;

procedure TrdmKnjigaIzdanihRacunov.SetDefaultExpression(DataSet: TDataSet);
begin
  inherited;
  if DataSet = dsMain then
  begin
    with DataSet do
    begin
      FieldByName('VREDNOST_Z_DDV').DefaultExpression := '0';
      FieldByName('OP_PR_BREZ_ODB').DefaultExpression := '0';
      FieldByName('OP_PR_IZVOZ').DefaultExpression := '0';
      FieldByName('OP_PR_Z_ODB').DefaultExpression := '0';
      FieldByName('OB_PR_DZ_ZS_OSNOVA').DefaultExpression := '0';
      FieldByName('OB_PR_DZ_ZS_DDV').DefaultExpression := '0';
      FieldByName('OB_PR_DZ_OS_OSNOVA').DefaultExpression := '0';
      FieldByName('OB_PR_DZ_OS_DDV').DefaultExpression := '0';
      FieldByName('OB_PR_KP_ZS_OSNOVA').DefaultExpression := '0';
      FieldByName('OB_PR_KP_ZS_DDV').DefaultExpression := '0';
      FieldByName('OB_PR_KP_OS_OSNOVA').DefaultExpression := '0';
      FieldByName('OB_PR_KP_OS_DDV').DefaultExpression := '0';
      FieldByName('ROCNO').DefaultExpression := '''N''';
    end
  end;
end;

procedure TrdmKnjigaIzdanihRacunov.Set_ReadOnly(Value: WordBool);
begin
  inherited;
end;

procedure TrdmKnjigaIzdanihRacunov.Set_SQLConnection(Value: Integer);
begin
  inherited;
end;

class procedure TrdmKnjigaIzdanihRacunov.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
  if Register then
  begin
    inherited UpdateRegistry(Register, ClassID, ProgID);
    EnableSocketTransport(ClassID);
    EnableWebTransport(ClassID);
  end else
  begin
    DisableSocketTransport(ClassID);
    DisableWebTransport(ClassID);
    inherited UpdateRegistry(Register, ClassID, ProgID);
  end;
end;

initialization
  KnjigaIzdanihRacunovFactory := TComponentFactory.Create(ComServer, TrdmKnjigaIzdanihRacunov,
    Class_rdmKnjigaIzdanihRacunov, ciInternal, tmApartment);
end.
